<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="course" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{courseHome.managed ? 'Edit' : 'Add'} Course</f:facet>


            <s:decorate id="idField" template="layout/edit.xhtml">
                <ui:define name="label">Id</ui:define>
                <h:inputText id="id"
                       required="true"
                       disabled="#{courseHome.managed}"
                          value="#{courseHome.instance.id}">
                    <a:support event="onblur" reRender="idField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>



            <s:decorate id="courseNameField" template="layout/edit.xhtml">
                <ui:define name="label">Course name</ui:define>
                <h:inputText id="courseName"
                           size="50"
                      maxlength="50"
                          value="#{courseHome.instance.courseName}">
                    <a:support event="onblur" reRender="courseNameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="detailsField" template="layout/edit.xhtml">
                <ui:define name="label">Details</ui:define>
                <h:inputTextarea id="details"
                               cols="80"
                               rows="10"
                              value="#{courseHome.instance.details}"/>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{courseHome.persist}"
                       disabled="#{!courseHome.wired}"
                       rendered="#{!courseHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{courseHome.update}"
                       rendered="#{courseHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{courseHome.remove}"
                      immediate="true"
                       rendered="#{courseHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Course.xhtml"
                rendered="#{courseHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty courseFrom ? 'CourseList' : courseFrom}.xhtml"
                rendered="#{!courseHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Teacher">
    <div class="association" id="teacherParent">

        <h:outputText value="There is no teacher associated with this course."
                   rendered="#{courseHome.instance.teacher == null}"/>

        <rich:dataTable var="_teacher"
                   value="#{courseHome.instance.teacher}"
                rendered="#{courseHome.instance.teacher != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="teacherTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_teacher.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">UserAccount id</f:facet>
                <h:outputText value="#{_teacher.userAccount.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Address by present address id id</f:facet>
                <h:outputText value="#{_teacher.addressByPresentAddressId.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Address by permanent address id id</f:facet>
                <h:outputText value="#{_teacher.addressByPermanentAddressId.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">First name</f:facet>
                <h:outputText value="#{_teacher.firstName}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Last name</f:facet>
                <h:outputText value="#{_teacher.lastName}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Passport photo url</f:facet>
                <h:outputText value="#{_teacher.passportPhotoUrl}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Subject</f:facet>
                <h:outputText value="#{_teacher.subject}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Date of birth</f:facet>
                <h:outputText value="#{_teacher.dateOfBirth}">
                    <s:convertDateTime type="date" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Qualification</f:facet>
                <h:outputText value="#{_teacher.qualification}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Mobile number</f:facet>
                <h:outputText value="#{_teacher.mobileNumber}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Contact number in case of emergency</f:facet>
                <h:outputText value="#{_teacher.contactNumberInCaseOfEmergency}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Comments</f:facet>
                <h:outputText value="#{_teacher.comments}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            
            <s:button id="#{courseHome.instance.teacher != null ? 'changeParentteacher' : 'selectParentteacher'}" value="#{courseHome.instance.teacher != null ? 'Change' : 'Select'} teacher"
                       view="/TeacherList.xhtml">
                       
                       
                <f:param name="from" value="CourseEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Students">
        <h:form styleClass="association" id="studentsChildren">

            <h:outputText value="There are no students associated with this course."
                       rendered="#{empty courseHome.students}"/>

            <rich:dataTable value="#{courseHome.students}"
                           var="_student"
                      rendered="#{not empty courseHome.students}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="studentsTable">
                <rich:column sortBy="#{_student.id}">
                    <f:facet name="header">Id</f:facet>
                    <h:outputText value="#{_student.id}"/>
                </rich:column>
                <rich:column sortBy="#{_student.firstName}">
                    <f:facet name="header">First name</f:facet>
                    <h:outputText value="#{_student.firstName}"/>
                </rich:column>
                <rich:column sortBy="#{_student.lastName}">
                    <f:facet name="header">Last name</f:facet>
                    <h:outputText value="#{_student.lastName}"/>
                </rich:column>
                <rich:column sortBy="#{_student.passportPhotoUrl}">
                    <f:facet name="header">Passport photo url</f:facet>
                    <h:outputText value="#{_student.passportPhotoUrl}"/>
                </rich:column>
                <rich:column sortBy="#{_student.dateOfBirth}">
                    <f:facet name="header">Date of birth</f:facet>
                    <h:outputText value="#{_student.dateOfBirth}">
                        <s:convertDateTime type="date" dateStyle="short"/>
                    </h:outputText>
                </rich:column>
                <rich:column sortBy="#{_student.registerNumber}">
                    <f:facet name="header">Register number</f:facet>
                    <h:outputText value="#{_student.registerNumber}"/>
                </rich:column>
                <rich:column sortBy="#{_student.rollNumber}">
                    <f:facet name="header">Roll number</f:facet>
                    <h:outputText value="#{_student.rollNumber}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{courseHome.managed}" id="students">
        <div class="actionButtons">
            <s:button id="addstudent"
                   value="Add student"
                    view="/StudentEdit.xhtml"
             propagation="none">
                 <f:param name="courseId"
                         value="#{courseHome.instance.id}"/>
                 <f:param name="studentFrom" value="Course"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
